<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('分润单号列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="ordernumber"/>
                            </li>
                            <li>
                                <label>建单日期：</label>
                                <input type="text" class="time-input" placeholder="建单日期" name="indate" />
                            </li>
                           <!-- <li>
                                <label>订单状态：</label>
                                <select name="state" th:with="type=${@dict.getType('order_status')}" th:checked="3">
                                    <option value="3">服务商确认</option>
                                </select>
                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-primary single disabled" onclick="examineAgent()" shiro:hasPermission="agentInfo:profitSbOrder:examine">
                    <i class="fa fa-edit"></i> 审核通过
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var exportFlag = [[${@permission.hasPermi('agentInfo:profitSbOrder:exportDetailExcel')}]];
        var lookDetailFlag = [[${@permission.hasPermi('agentInfo:profitSbOrder:looksDetails')}]];
        var stateDatas = [[${@dict.getType('order_status')}]];
        var ordertypeDatas = [[${@dict.getType('nature')}]];
        var prefix = ctx + "agentInfo/profitSbOrder";

        $(function() {
            var options = {
                url: prefix + "/list",
                clickToSelect: true,
                exportUrl: prefix + "/export",
                modalName: "分润单号",
                queryParams:queryParams,
                columns: [{
                    radio: true
                },
                {
                    field: 'ordernumber',
                    title: '订单号'
                },
                {
                    field: 'sumtrade',
                    title: '出款总户数'
                },
                {
                    field: 'sumcount',
                    title: '出款总笔数'
                },
                {
                    field: 'payMoney',
                    title: '应出款金额',
                    formatter: function(value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },
                {
                    field: 'remittanceWay',
                    title: '出款方式',
                    formatter: function(value, row, index) {
                        if ("0"==value){
                            return '<span style="color:blue;">平台接口出款</span>';
                        }else if("1"==value){
                            return '<span style="color:green;">代付出款</span>';
                        }
                    }
                },
                {
                    field: 'addBillsPerson',
                    title: '创建人'
                },
                {
                    field: 'paymoneyPerson',
                    title: '出款人'
                },
                {
                    field: 'checkPerson',
                    title: '复核人'
                },
                {
                    field: 'state',
                    title: '审核状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(stateDatas, value);
                    }
                },
                {
                    field: 'remittanceBank',
                    title: '系统支付行号'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'indate',
                    title: '生成日期'
                },
                {
                    field: 'ordertype',
                    title: '订单类型',
                    formatter: function(value, row, index) {
                        if ("1"==value){
                            return '<span style="color:blue;">对公</span>';
                        }else if("2"==value){
                            return '<span style="color:green;">对私</span>';
                        }
                    }
                },
                {
                    field: 'sumamount',
                    title: '交易总金额',
                    formatter: function(value, row, index) {
                        return $.table.rmbFormatter(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + exportFlag + '" href="javascript:void(0)" onclick="exportDetailExcel(\'' + row.ordernumber + '\')"><i class="fa fa-download"></i>导出明细</a> ');
                        actions.push('<a class="btn btn-default btn-xs ' + lookDetailFlag + '" href="javascript:void(0)" onclick="looksDetails(\'' + row.ordernumber + '\')"><i class="fa fa-edit"></i>查看详情</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.state = '3';
            return search;
        }

        /**
         * 导出明细
         * @param orderNumber
         */
        function exportDetailExcel(orderNumber){
            $.modal.loading("正在导出数据，请稍后...");
            var dataParam = {"ordernumber":orderNumber};
            $.post(prefix+"/exportDetailExcel", dataParam, function(result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess(result.msg);
                    // window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        }

        /**
         * 查看详情
         */
        function looksDetails(orderNumber) {
            $.modal.openTab("查看详情", prefix+"/looksDetails/"+orderNumber);
        }
        
        function examineAgent() {
            var rows = $.table.selectColumns("ordernumber");
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要审核通过选中的数据吗?", function() {
                var data = { "ordernumber": rows.join() };
                $.operate.submit(prefix + "/examineAgent", "post", "json", data);
            });
        }
    </script>
</body>
</html>